package name.gauravmadan.mdg.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import name.gauravmadan.mdg.pim.Application;
import name.gauravmadan.mdg.pim.Association;
import name.gauravmadan.mdg.pim.Attribute;
import name.gauravmadan.mdg.pim.Class;
import name.gauravmadan.mdg.pim.Component;

public class ModelDataServiceImpl  extends SqlMapClientDaoSupport implements ModelDataService { //extends SqlMapClientDaoSupport
	private Application application;
	private SequenceDaoImpl sequenceDao;
	
	public final String SEQ_APPLICATION="SEQ_APPLICATION";
	public final String SEQ_COMPONENT="SEQ_COMPONENT";
	public final String SEQ_CLASS="SEQ_CLASS";
	public final String SEQ_ATTRIBUTE="SEQ_ATTRIBUTE";
	public final String SEQ_ASSOCIATION = "SEQ_ASSOCIATION";
	
	public Application getApplication() {
		return application;
	}

	public void setApplication(Application application) {
		this.application = application;
	}

	public void createApplication(Application application) {
		int id = sequenceDao.getNextId(SEQ_APPLICATION);
		application.setId(new Integer(id));
		getSqlMapClientTemplate().insert("insertApplication",application);
	}

	public void createAttribute(Attribute attribute) {
		int id = sequenceDao.getNextId(SEQ_ATTRIBUTE);
		attribute.setId(new Integer(id));
		getSqlMapClientTemplate().insert("insertAttribute",attribute);
	}
	
	public void createAssociation(Association association) {
		int id = sequenceDao.getNextId(SEQ_ASSOCIATION);
		association.setId(new Integer(id));
		getSqlMapClientTemplate().insert("insertAssociation",association);
	}
	
	public void createClass(Class clazz) {
		int id = sequenceDao.getNextId(SEQ_CLASS);
		clazz.setId(new Integer(id));
		getSqlMapClientTemplate().insert("insertClass",clazz);
	}

	public void createComponent(Component component) {
		int id = sequenceDao.getNextId(SEQ_COMPONENT);
		component.setId(new Integer(id));
		getSqlMapClientTemplate().insert("insertComponent", component);
	}

	public void deleteApplicationById(Integer id) {
		getSqlMapClientTemplate().delete("deleteApplication", id);
	}

	public void deleteAttributeById(Integer id) {
		getSqlMapClientTemplate().delete("deleteAttribute", id);
	}

	public void deleteAssociationById(Integer id) {
		getSqlMapClientTemplate().delete("deleteAssociation", id);
	}
	
	public void deleteClassById(Integer id) {
		getSqlMapClientTemplate().delete("deleteClass", id);
	}

	public void deleteComponentById(Integer id) {
		getSqlMapClientTemplate().delete("deleteComponent", id);
	}

	public Application getApplicationById(Integer id) {
		return (Application) getSqlMapClientTemplate().queryForObject("getApplicationById",id);
	}

	public List<Application> getApplicationList() {
		return (List<Application>) getSqlMapClientTemplate().queryForList("getApplicationList");
	}

	public Attribute getAttributeById(Integer id) {
		return (Attribute)getSqlMapClientTemplate().queryForObject("getAttributeById", id);
	}

	public Association getAssociationById(Integer id) {
		return (Association)getSqlMapClientTemplate().queryForObject("getAssociationById", id);
	}
	
	public List<Attribute> getAttributeListByClassId(Integer id) {
		return (List<Attribute>)getSqlMapClientTemplate().queryForList("getAttributeListByClassId",id);
	}

	public List<Association> getAssociationListByClassId(Integer id) {
		return (List<Association>)getSqlMapClientTemplate().queryForList("getAssociationListByClassId",id);
	}
	
	public Class getClassById(Integer id) {
		return (Class)getSqlMapClientTemplate().queryForObject("getClassById", id);
	}

	public List<Class> getClassListByCompId(Integer id) {
		return (List<Class>)getSqlMapClientTemplate().queryForList("getClassListByCompId", id);
	}

	public Component getComponentById(Integer id) {
		return (Component)getSqlMapClientTemplate().queryForObject("getComponentById", id);
	}

	public List<Component> getComponentListByAppId(Integer id) {
		return (List<Component>)getSqlMapClientTemplate().queryForList("getComponentListByAppId", id);
	}

	public void updateApplication(Application application) {
		getSqlMapClientTemplate().update("updateApplication", application);

	}

	public void updateAttribute(Attribute attribute) {
		getSqlMapClientTemplate().update("updateAttribute", attribute);
	}

	public void updateAssociation(Association association) {
		getSqlMapClientTemplate().update("updateAssociation", association);
	}
	
	public void updateClass(Class clazz) {
		getSqlMapClientTemplate().update("updateClass",clazz);
	}

	public void updateComponent(Component component) {
		getSqlMapClientTemplate().update("updateComponent", component);
	}

	public SequenceDaoImpl getSequenceDao() {
		return sequenceDao;
	}

	public void setSequenceDao(SequenceDaoImpl sequenceDao) {
		this.sequenceDao = sequenceDao;
	}
	
}
